#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

bool closeStrings(string word1, string word2) {
    vector<int> count1(26), count2(26);
    for (auto it : word1)
        count1[it - 'a']++;
    for (auto it : word2)
        count2[it - 'a']++;

    for (int i = 0; i < 26; i++)
        if (count1[i] > 0 && count2[i] == 0 || count1[i] == 0 && count2[i] > 0)
            return false;

    sort(count1.begin(), count1.end());
    sort(count2.begin(), count2.end());

    return count1 == count2;
}